package com.sinohealth.sca.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

/**
 * @Description: 线程池配置类
 * @Package: com.sinohealth.sca.config
 * @Author: chenweifeng
 * @Date: 2024/04/07 下午2:01
 **/
@Configuration
@EnableAsync
public class ThreadPoolConfig {

    @Bean(name = "handleMessageThreadPool")
    public TaskExecutor handleMessageThreadPool() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(10);
        taskExecutor.setMaxPoolSize(20);
        taskExecutor.setQueueCapacity(100);
        taskExecutor.setKeepAliveSeconds(60);
        taskExecutor.setThreadNamePrefix("handleMessageThreadPool-");
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Bean(name = "processQueueThreadPool")
    public TaskExecutor processQueueThreadPool() {
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(5);
        taskExecutor.setMaxPoolSize(10);
        taskExecutor.setQueueCapacity(20);
        taskExecutor.setKeepAliveSeconds(30);
        taskExecutor.setThreadNamePrefix("processQueueThreadPool-");
        taskExecutor.initialize();
        return taskExecutor;
    }
}